import { ref } from 'vue'
import { saveType } from '@/api/basic'
import { UpdateNetworkTypeFrom } from './types'

export default () => {
  const updateNetworkTypeForm = ref<UpdateNetworkTypeFrom>({
    id: '',
    name: '',
    parentId: '',
    status: false,
  })

  const updateNetworkTypeLoading = ref(false)

  const updateNetworkType = async () => {
    updateNetworkTypeLoading.value = true
    const res = await saveType(updateNetworkTypeForm.value)
    updateNetworkTypeLoading.value = false
    return res.data as { code: number; data: object; message: string; success: boolean }
  }

  const resetUpdateNetworkTypeForm = () => {
    updateNetworkTypeForm.value = {
      id: '',
      name: '',
      parentId: '',
      status: false,
    }
  }

  return {
    updateNetworkTypeForm,
    updateNetworkTypeLoading,
    updateNetworkType,
    resetUpdateNetworkTypeForm,
  }
}
